<?php $this->load->view("common/page_header");?>


<div class="form_border user_register">
	<div class="clear"></div>
	<form action="/user/register" method="post" id="register-form">
		<div class="form_row">
			<label class="input_label" for="nickname"><span class="red">*</span> 昵称：</label><input type="text" class="input_text" name="nickname" id="nickname" value="<?php echo empty($nickname) ? '' : $nickname;?>"/>
			<div class="form_tip">6-20个字母、数字、汉字组合</div>
			<div class="form_error"></div>
			<div class="form_right"></div>
			<div class="clear"></div>
		</div>
		<div class="form_row">
			<label class="input_label" for="password"><span class="red">*</span> 密码：</label><input type="password" class="input_text" name="password" id="password"/>
			<div class="form_tip">6-16个字符</div>
			<div class="clear"></div>
			<div class="form_error"></div>
			<div class="form_right"></div>
		</div>
		<div class="form_row">
			<label class="input_label" for="confirm_password"><span class="red">*</span> 确认密码：</label><input type="password" class="input_text" name="confirm_password" id="confirm_password"/>
			<div class="form_tip">6-16个字符</div>
			<div class="clear"></div>
			<div class="form_error"></div>
			<div class="form_right"></div>
		</div>
		<div class="form_row">
			<label class="input_label" for="email"><span class="red">*</span> email：</label><input type="text" class="input_text" name="email" id="email"  value="<?php echo empty($email) ? '' : $email;?>"/>
			<div class="form_tip">请输入您的常用邮箱</div>
			<div class="clear"></div>
			<div class="form_error"></div>
			<div class="form_right"></div>
		</div>
		<div class="form_row">
			<label class="input_label" for="captcha"><span class="red">*</span> 验证码：</label><input type="input" class="input_text" name="captcha" id="captcha"/>
			<div class="right" id="captcha-image"><?php echo $captcha['image'];?></div>
			<div class="clear"></div>
		</div>
		<div class="form_action">
			<input type="checkbox" name="agree_protocal" id="agree_protocal" class="input_checkbox" checked><label>同意《<a target="_blank" class="underline" href="<?php echo site_url("/protocal.html")?>">行动网络服务使用协议</a>》</label>
			<div class="right"><a href="###" id="reset-captcha">看不清，换一换</a></div>
		</div>
		<div class="form_action">
			<input type="hidden" name="from" value="ajax"></input>
			<input type="button" id="submit-button" class="input_button" value="注册行动网帐号" />
			<span id="register-info" class="margin_left10 red"></span>
		</div>
	</form>
</div>
<script type="text/javascript">
$(document).ready(function(){
	$("#submit-button").click(function() {
		if ($(this).closest('form').find('.form_error').is(':visible') || $('#nickname').val() == '') {
		} else {
			$.post("/user/register", $("#register-form").serialize(),function(data){
				if (data == 1) {
					$("#register-info").html("注册成功，请到注册邮箱内激活帐号");
					setTimeout("close_colorbox()", 2000);
					
				} else if (data ==2) {
					$("#register-info").html("此用户已经被注册");
				}  else if (data ==3){
					$("#register-info").html("密码与确认密码不一致");
				} else if (data == 4 ) {
					$("#register-info").html("验证码输入错误");
				} else {
					alert("注册失败，请稍候再试");
				}
			});
		}
	});
	$('#agree_protocal').click(function(){
		if ($(this).attr('checked')) {
			$('#submit-button').attr('disabled', false).removeClass('disabled');
		} else {
			$('#submit-button').attr('disabled', true).addClass('disabled');
		}
			
	});
	$('#reset-captcha').click(function(){
		$.get('/user/reset_captcha',  function(data) {
			$('#captcha-image').html(data);
		})	
	});
	$('#nickname').blur(function(){
		var $this = $(this);
		var nick = $this.val();
		var parent = $this.parent();
		if (nick == '') {
			parent.find('.form_error').html('<div class="error_icon"></div>昵称不能为空').show();
			parent.find('.form_right').hide();
		} else if (!/^[_0-9a-z\u4e00-\u9fa5]+$/gi.test(nick)) {
			parent.find('.form_error').html('<div class="error_icon"></div>昵称不能包括特殊字符').show();
			parent.find('.form_right').hide();
		} else if (nick.length < 6 || nick.length > 20) {
			parent.find('.form_error').html('<div class="error_icon"></div>昵称要在6-20个字符内').show();
			parent.find('.form_right').hide();
		} else {
			$.get('/user/ajax_user_check', {type:'nick', value:nick}, function(data) {
				var data = eval('(' + data + ')');
				if (data.result == '1') {
					parent.find('.form_error').html('<div class="error_icon"></div>此用户名已被使用').show();
					parent.find('.form_right').hide();
				} else {
					parent.find('.form_right').html('<div class="right_icon"></div>此用户名可以使用').show();
					parent.find('.form_error').hide();
				}
			})
		}
	});
	$('#password').blur(function() {
		var $this = $(this);
		var password = $('#password').val();
		var parent = $this.parent();
		if (password == '') {
			parent.find('.form_error').html('<div class="error_icon"></div>密码不能为空').show();
			parent.find('.form_right').hide();
		} else if (password.length < 6 || password.length > 16) {
			parent.find('.form_error').html('<div class="error_icon"></div>密码要在6-16个字符内').show();
			parent.find('.form_right').hide();
		} else {
			parent.find('.form_right').html('<div class="right_icon"></div>密码正确').show();
			parent.find('.form_error').hide();
		}
	});
	$('#confirm_password').blur(function() {
		var $this = $(this);
		var password = $('#password').val();
		var confirm_password = $this.val();
		var parent = $this.parent();
		if (confirm_password == '') {
			parent.find('.form_error').html('<div class="error_icon"></div>密码不能为空').show();
			parent.find('.form_right').hide();
		} else if (confirm_password != password) {
			parent.find('.form_error').html('<div class="error_icon"></div>两次输入密码不一致').show();
			parent.find('.form_right').hide();
		} else {
			parent.find('.form_right').html('<div class="right_icon"></div>确认密码正确').show();
			parent.find('.form_error').hide();
		}
	});
	$('#email').blur(function(){
		var $this = $(this);
		var email = $this.val();
		var parent = $this.parent();
		if (email == '' || !/^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/gi.test(email)) {
			parent.find('.form_error').html('<div class="error_icon"></div>邮箱格式不对').show();
			parent.find('.form_right').hide();
		} else {
			$.get('/user/ajax_user_check', {type:'email', value:email}, function(data) {
				var data = eval('(' + data + ')');
				if (data.result == '1') {
					parent.find('.form_error').html('<div class="error_icon"></div>此邮箱已被使用').show();
					parent.find('.form_right').hide();
				} else {
					parent.find('.form_right').html('<div class="right_icon"></div>此邮箱可以使用').show();
					parent.find('.form_error').hide();
				}
			})
		}
	});
});
function close_colorbox() {
	$.colorbox.close();
	parent.location.reload();
}
</script>
<?php $this->load->view("common/page_footer");?>